package main

import "fmt"

func main() {
	//声明切片
	s := make([]string, 3)
	fmt.Println("emp：", s)

	//赋值，取值，长度类似数组
	s[0] = "a"
	s[1] = "b"
	s[2] = "c"
	fmt.Println("set:", s)
	fmt.Println("get:", s[2])
	fmt.Println("len:", len(s))

	//append函数得到新的切片
	s = append(s, "d")
	s = append(s, "e", "f")
	fmt.Println("apd:", s)

	//copy函数复制切片
	c := make([]string, len(s))
	copy(c, s)
	fmt.Println("cpy:", c)

	//slices[low.high]，输出从low到high的值，只包含下标low的，不包含下标high
	l := s[2:5]
	fmt.Println("s[2:5]:", l)
	l = s[:5]
	fmt.Println("s[:5]:", l)
	l = s[2:]
	fmt.Println("s[2:]:", l)

	//声明并初始化
	t := []string{"g", "h", "i"}
	fmt.Println(t)

	//二维切片
	twoD := make([][]int, 3)
	for i := 0; i < 3; i++ {
		innerLen := i + 1
		//内部切片声明
		twoD[i] = make([]int, innerLen)
		for j := 0; j < innerLen; j++ {
			twoD[i][j] = i + j
		}
	}
	fmt.Println("2d:", twoD)

}
